﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SEVN.Web.Framework.Modules.News
{
    public partial class CateNews0501 : System.Web.UI.UserControl
    {
        WebFrameDataContext dt = new WebFrameDataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            RPTCategory.DataSource = dt.Categories.Where(x => x.IsFontPage == true);
            RPTCategory.DataBind();
        }

        protected void RPTCategory_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            HiddenField hf = (HiddenField)e.Item.FindControl("hf");
            Repeater rptcon = (Repeater)e.Item.FindControl("RPTLeft");
            if (rptcon != null && hf != null)
            {
                rptcon.DataSource = dt.Newsletters.Where(x => x.CategoryID.ToString() == hf.Value).Take(1).OrderByDescending(x => x.CreateDate);
                rptcon.DataBind();
            }
            DataList datalist = (DataList)e.Item.FindControl("DTLContent");
            if (hf != null && datalist != null)
            {
                datalist.DataSource = dt.Newsletters.Where(x => x.CategoryID.ToString() == hf.Value).Take(5).Skip(1).OrderByDescending(x => x.CreateDate).Select(x => new
                {
                    x.Image,
                    Title = x.Title.Substring(0, 60),
                    SubTitle = x.SubTitle.Substring(0, 80),
                });
                datalist.DataBind();
            }
            Repeater rp = (Repeater)e.Item.FindControl("Cate0501ContentRelate");
            if (hf != null && rp != null)
            {
                rp.DataSource = dt.Newsletters.Where(x => x.CategoryID.ToString() == hf.Value).OrderByDescending(x => x.CreateDate).Take(9).Skip(5).Select(x => new
                    {
                        x.CategoryID,
                        Title = x.Title.Substring(0, 80),
                        x.NewsID
                    });
                rp.DataBind();
            }
            Repeater rpl = (Repeater)e.Item.FindControl("RPTCateLeft");
            if (rpl != null && rpl != null)
            {
                rpl.DataSource = dt.Categories.Where(x => x.CategoryParentID.ToString() == hf.Value).Take(3);
                rpl.DataBind();
            }


        }
    }
}